import os
import sys

def backup(read_file, write_file, want_delete = None):
	reader = None
	writer = None

	try:
		reader = open(read_file, "r");
	except:
		print("Didn't found file " + read_file)
		return 1

	try:
		writer = open(write_file, "r");
	except:
		print("Didn't found file " + write_file)
		return 1

	for write_dir in writer:
		for read_dir in reader:
			command = str()
			if(want_delete is None):
				command = "rsync -P -t --recursive " + read_dir[:-1] + " " + write_dir[:-1]
			else:
				command = "rsync -P -t --recursive --delete " + read_dir[:-1] + " " + write_dir[:-1]
			os.system(command)

if __name__ == "__main__" :
	if(len(sys.argv) == 3):
		backup(sys.argv[1], sys.argv[2])
	elif(len(sys.argv) == 4 and sys.argv[2] == "--delete"):
		backup(sys.argv[2], sys.argv[3], sys.argv[2])
	else:
		print("Use pyback read_file write_file")
